package com.entity;

import com.enumeration.ResponseEnum;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * Response.java
 *
 * @author Liang 649355204@qq.com
 * CreateTime 2019/7/10 16:48
 */
@Component
public class Response {
    /** 返回代码 */
    private int resultCode;
    /** 返回信息 */
    // private String
    private String resultMsg;
    /** 返回具体数据 */
    private Map<String, Object> data;
    /** 错误代码 */
    private int errCode;
    /** 错误信息 */
    private String errMsg;

    public Response() {
        this.data = new HashMap<>();
    }
    /**
     * 追加data键值对
     * @param key 键名
     * @param value 值
     *
     * */
    public Response appendMsg(String key, Object value) {
        this.data.put(key, value);
        return this;
    }
    public Response setSuccess() {
        this.resultCode = ResponseEnum.OK.getCode();
        this.resultMsg = ResponseEnum.OK.getMsg();
        return this;
    }
    public Response setFailed() {
        this.resultCode = ResponseEnum.FAILED.getCode();
        this.resultMsg = ResponseEnum.FAILED.getMsg();
        return this;
    }

    public Response setParamError() {
        this.errCode = ResponseEnum.PARAMETER_MISSING.getCode();
        this.errMsg = ResponseEnum.PARAMETER_MISSING.getMsg();
        return this;
    }

    public Response(int resultCode, String resultMsg, Map<String, Object> data, int errCode, String errMsg) {
        this.resultCode = resultCode;
        this.resultMsg = resultMsg;
        this.data = data;
        this.errCode = errCode;
        this.errMsg = errMsg;
    }

    public int getResultCode() {
        return resultCode;
    }

    public Response setResultCode(int resultCode) {
        this.resultCode = resultCode;
        return this;
    }

    public String getResultMsg() {
        return resultMsg;
    }

    public Response setResultMsg(String resultMsg) {
        this.resultMsg = resultMsg;
        return this;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public Response setData(Map<String, Object> data) {
        this.data = data;
        return this;
    }

    public int getErrCode() {
        return errCode;
    }

    public Response setErrCode(int errCode) {
        this.errCode = errCode;
        return this;
    }

    public String getErrMsg() {
        return errMsg;
    }

    public Response setErrMsg(String errMsg) {
        this.errMsg = errMsg;
        return this;
    }

}
